package com.xishu.dao.jpa;

import com.xishu.entity.customer.SendHistory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.persistence.Tuple;
import java.util.List;

public interface SendHistoryDao extends JpaRepository<SendHistory, Long>, JpaSpecificationExecutor<SendHistory> {


    /**
     * 统计发送的数量
     * <p>
     * <p>
     * 按照shopId以及年龄来分组
     *
     * @param startTime
     * @param endTime
     * @param
     * @return
     */
    @Query(value = "select FROM_UNIXTIME(create_time / 1000,'%Y-%m-%d')  as x , count(send_number) as value " +
            "from send_history where  create_time >= :startTime and create_time <= :endTime " +
            " and sms = :sms " +
            " and email = :email " +
            " and plan = :plan " +
            " and company_id = :companyId " +
            " group by company_id,FROM_UNIXTIME(create_time / 1000, '%Y-%m-%d') ",
            nativeQuery = true)
    public List<Tuple> countSend(@Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("companyId") Long companyId,
                                         @Param("sms") Boolean sms, @Param("email") Boolean email, @Param("plan") Boolean plan);

}
